home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / HyperCuber 2.0 / source / HideMenuBar.c < prev    next >
Encoding:
Text File  |  1993-08-31  |  4.2 KB  |  156 lines  |  [TEXT/KAHL]

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| HideMenuBar.c
  3. //|
  4. //| This contains a collection of routines which hide or display the menu bar.
  5. //| This code was adapted from Pascal code by Earle R. Horton.  The original
  6. //| Pascal source contained the following paragraph:
  7. //|
  8. //|   This file is part of Earle R. Horton's private source code library.
  9. //|   Earle R. Horton assumes no responsibility for any damages arising
  10. //|   out of use of this source code for any purpose.  Earle R. Horton
  11. //|   places no restrictions on use of all or any part of this source code,
  12. //|   except that this paragraph may not be altered or removed.
  13. //|____________________________________________________________________________
  14.  
  15.  
  16.  
  17. //=============================== Globals ===============================\\
  18.  
  19. RgnHandle    save_region;
  20. short        menubar_height;
  21. Rect        menubar_rect;
  22. Boolean        menubar_hidden;
  23.  
  24. //=============================== Prototypes ===============================\\
  25.  
  26. void init_menubar(void);
  27. void show_menubar(void);
  28. void hide_menubar(void);
  29. void set_menubar_height(short new_height);
  30.  
  31.  
  32. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. //| Procedure set_menubar_height
  34. //|
  35. //| Purpose: Set the height of the menubar.  This modifies a low-memory global
  36. //|
  37. //| Parameters: new_height: desired height of the menubar
  38. //|____________________________________________________________________________
  39.  
  40. void set_menubar_height(short new_height)
  41. {
  42.  
  43. asm    {
  44.     
  45.     move.w    new_height, 0x0BAA        //  Update menubarheight global
  46.     
  47.     }    
  48.  
  49. }    //==== set_menubar_height() ====\\
  50.  
  51.  
  52.  
  53. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. //| Procedure init_menubar
  55. //|
  56. //| Purpose: Initialize globals in preparation for an eventual call to hide_menubar
  57. //|
  58. //| Parameters: none
  59. //|_________________________________________________________________________________
  60.  
  61. void init_menubar(void)
  62. {
  63.  
  64.     menubar_hidden = FALSE;                //  Menubar starts visible
  65.     menubar_height = GetMBarHeight();    //  Get the height of the menu bar
  66.     SetRect(&menubar_rect,                //  Compute menu bar's rectangle
  67.                 screenBits.bounds.left,
  68.                 screenBits.bounds.top,
  69.                 screenBits.bounds.right,
  70.                 screenBits.bounds.top + menubar_height);
  71.  
  72. }    //==== init_menubar() ====\\
  73.  
  74.  
  75.  
  76. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. //| Procedure hide_menubar
  78. //|
  79. //| Purpose: Hide the menu bar
  80. //|
  81. //| Parameters: none
  82. //|_________________________________________________________________________________
  83.  
  84. void hide_menubar(void)
  85. {
  86.  
  87.     RgnHandle    menubar_region;
  88.     WindowPeek    window;
  89.  
  90.     if (!menubar_hidden)
  91.         {
  92.         
  93.         save_region = NewRgn();                    //  Initialize Region where we'll save GrayRgn
  94.         
  95.         menubar_region = NewRgn();                //  Initialize menu bar region
  96.         
  97.         set_menubar_height(0);                    //  Set menubar to zero height
  98.         
  99.         CopyRgn(GetGrayRgn(), save_region);        //  Get a copy of GrayRgn
  100.         
  101.         RectRgn(menubar_region, &menubar_rect);    //  Set GrayRgn to original GrayRgn plus menu bar
  102.         UnionRgn(GetGrayRgn(), menubar_region,
  103.                     GetGrayRgn());
  104.         
  105.         window = (WindowPeek) FrontWindow();    //  Fix any windows which were behind menubar
  106.         PaintOne(window, menubar_region);
  107.         CalcVis(window);
  108.         CalcVisBehind(window, menubar_region);
  109.         
  110.         DisposeRgn(menubar_region);                //  Get rid of menubar region
  111.         
  112.         menubar_hidden = TRUE;                    //  Menubar is now hidden
  113.         
  114.         }
  115.  
  116. }    //==== hide_menubar() ====\\
  117.  
  118.  
  119.  
  120. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. //| Procedure show_menubar
  122. //|
  123. //| Purpose: Show the menu bar
  124. //|
  125. //| Parameters: none
  126. //|_________________________________________________________________________________
  127.  
  128. void show_menubar()
  129. {
  130.  
  131.     WindowPeek    window;
  132.     
  133.     if (menubar_hidden)
  134.         {
  135.         menubar_hidden = FALSE;                    //  Menu bar is no longer hidden
  136.         
  137.         CopyRgn(save_region, GetGrayRgn());        //  Restore old GrayRgn
  138.         
  139.         set_menubar_height(menubar_height);        //  Restore menubar height
  140.         
  141.         RectRgn(save_region, &menubar_rect);    //  Update any covered windows
  142.         window = (WindowPeek) FrontWindow();
  143.         CalcVis(window);
  144.         CalcVisBehind(window, save_region);
  145.         
  146.         DisposeRgn(save_region);                //  Get rid of the region used to save GrayRgn
  147.         
  148.         HiliteMenu(0);                            //  Draw the menubar
  149.         DrawMenuBar();
  150.         }
  151.  
  152. }    //==== show_menubar() ====\\
  153.  
  154.  
  155.  
  156.